import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const views = require.context('@/views', true, /\/.*\.vue$/)
console.info(views)

let generator = []
// 遍历文件名字
views.keys().map(key => { //eg: './Home.vue'
	// 生成对应的路由对象
	let route = {
		path: key.slice(1, -4).toLowerCase(),
		component: () => import(`@/views${key.slice(1)}`) //懒加载的！
	}
	generator.push(route)
})

const routes = [
  {
		path: '/',
		component: () => import('@/views/Home.vue')
	},
	...generator
]

const router = new VueRouter({
  routes
})

export default router
